package d3_interface_demo;

import java.util.ArrayList;

public class StudentOperatorImpl2 implements StudentOperator{
    @Override
    public void printAllInfo(ArrayList<Student> students){
        int boy = 0;
        int girl = 0;
        System.out.println("打印全部学生信息");
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            System.out.println("name:"+s.getName() + " sex:" + s.getSex() + " grade:" + s.getScore());
            if(s.getSex()=='男'){
                boy++;
            }
            else {
                girl++;
            }
        }
        System.out.println("boy:" + boy + " girl:" + girl);
    }

    @Override
    public void printAverageScore(ArrayList<Student> students){
        double allscore = 0.0;
        double max = students.get(0).getScore();
        double min = students.get(0).getScore();
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            allscore += s.getScore();
            if(s.getScore() > max){max = s.getScore();}
            if(s.getScore() < min){min = s.getScore();}
        }
        allscore = allscore - max - min;
        System.out.println("Average Score:" + allscore/(students.size()-2));
    }
}
